package com.zhangxin.aiInterview.utils;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 压力值存储
 */
@Component
public class StressManager {

    // 线程安全的全局 Map
    private final ConcurrentHashMap<Long, List<String>> stressMap = new ConcurrentHashMap<>();

    /**
     * 添加一个用户的压力字符串
     */
    public void addStress(Long userId, String stress) {
        stressMap.computeIfAbsent(userId, k -> Collections.synchronizedList(new ArrayList<>())).add(stress);
    }

    /**
     * 获取指定用户的所有压力记录
     */
    public List<String> getStress(Long userId) {
        return stressMap.getOrDefault(userId, new ArrayList<>());
    }

    /**
     * 清除指定用户的压力记录
     */
    public void clearStress(Long userId) {
        stressMap.remove(userId);
    }
}
